package com.netsdk.demo.customize;

import com.netsdk.demo.util.CaseMenu;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.enumeration.EM_NEW_CONFIG;
import com.netsdk.lib.enumeration.ENUMERROR;
import com.netsdk.lib.utils.Initialization;
import com.sun.jna.ptr.IntByReference;

public class EncodeConfigDemo extends Initialization {
    int channel = 0;
    static NetSDKLib netsdkApi = NetSDKLib.NETSDK_INSTANCE;
    static NetSDKLib configApi = NetSDKLib.CONFIG_INSTANCE;

    public boolean getEncodeConfig(){
        String cfgCmd = EM_NEW_CONFIG.CFG_CMD_ENCODE.getValue();
        NetSDKLib.CFG_ENCODE_INFO encodeInfo = new NetSDKLib.CFG_ENCODE_INFO();
        encodeInfo.nChannelID = channel;
        int nBufferLen = 2 * 1024 * 1024;
        byte[] strBuffer = new byte[nBufferLen];
        IntByReference error = new IntByReference(0);
        IntByReference retLen = new IntByReference(0);
        boolean ret = netsdkApi.CLIENT_GetNewDevConfig(loginHandle, cfgCmd, channel, strBuffer, nBufferLen, error, 5000);
        if (!ret) {
            System.err.println("获取远程设备编码配置失败:" + ENUMERROR.getErrorMessage());
            return false;
        } else {
            System.out.println(new String(strBuffer).trim());
        }
        return true;
    }

    /**
     * 加载测试内容
     */
    public void RunTest() {
        CaseMenu menu = new CaseMenu();
        menu.addItem(new CaseMenu.Item(this, "订阅智能事件", "AttachEventRealLoadPic"));
        menu.addItem(new CaseMenu.Item(this, "停止侦听智能事件", "DetachEventRealLoadPic"));
        menu.run();
    }

    public static void main(String[] args) {
        EncodeConfigDemo encodeConfigDemo=new EncodeConfigDemo();

        Initialization.InitTest("172.29.5.1", 37777, "admin", "admin123");

        encodeConfigDemo.RunTest();

        Initialization.LoginOut();
    }
}
